package com.yf.cn.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 自定义填充内容，根据属性名去填充数据
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("crtTime" ,LocalDateTime.now(),metaObject);
        this.setFieldValByName("upTime",LocalDateTime.now(),metaObject);
        this.setFieldValByName("version",1,metaObject);  //版本号创建的时候默认为1
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("upTime",LocalDateTime.now(),metaObject);
    }
}
